package com.itheima.Demo2hashmap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class HashMapDemo3 {
    public static void main(String[] args) {
        //统计80个同学的想去的景点
        ArrayList<String> location = new ArrayList<>();
        String []names={"西安","北京","上海","广州"};
        Random r = new Random();
        for(int i=0;i<80;i++)
        {
            int i1=r.nextInt(names.length);
            location.add(names[i1]);
        }
        System.out.println(location);
        Map<String,Integer> map = new HashMap<>();

        for (String location2 : location) {
            if(map.containsKey(location2))
            {
                map.put(location2,map.get(location2)+1);
            }
            else {
                map.put(location2,1);
            }
        }
        System.out.println(map);
    }
}
